function start(){
	//小图片的动作
	smallPicMove();
	function smallPicMove(){
		//划过效果
		$(".small_pic_list").find("li a").hover(function(){
			$(this).parent().css("border","1px solid #CC0000");
			$(this).parent().find(".sanjiao").css("display","block");
			$(this).parent().siblings().css("border","1px solid #d5d5d5");
			$(this).parent().siblings().find(".sanjiao").css("display","none");
		});
		//滚动效果
		$(".slideDown").on("click",function(){
			$(".small_pic_list").animate({"top":"-=80px"},600);
		});
		$(".slideUp").on("click",function(){
			$(".small_pic_list").animate({"top":"+=80px"},600);
		});
		//点击切换大图片
		$(".small_pic_list").find("li").on("click",function(){
			var $index = $(this).index();
			$(".deta_big_pic").find("li").eq($index).siblings().css("display","none");
			$(".deta_big_pic").find("li").eq($index).css("display","block");
			$(".glassPic").css("background","url(../img/bigpic"+ $index +".jpg) no-repeat")
		});
		//放大镜的移动
		var $wC = $(".clond_move").width(); //覆盖的宽高
		var $hC = $(".clond_move").height(); 
		var $wS = $(".deta_big_pic").width();//小图的宽高
		var $hS = $(".deta_big_pic").height();
		var scale = $wC*3.2/$hS;
		$(".deta_big_pic").on({"mousemove":function(event){
//			console.log("进去");
			$(".clond_move").css("display","block");
			$(".glassPic").stop().show();
			var mouseX = event.pageX-$(this).offset().left;
			var mouseY = event.pageY-$(this).offset().top;
//			console.log(mouseX+"----"+mouseY)
			if (mouseX>$wC/2 && mouseX<$wS-$wC/2) {//判断X轴，小放大镜出现的位置
				$(".clond_move").css("left",mouseX-$wC/2+"px")
				$(".glassPic").css("background-position-x","-"+(mouseX-$wC/2)*scale+'px');
			} else{
				if(mouseX<$wC/2){
					$(".clond_move").css("left","0px")
				}else{
					$(".clond_move").css("left",$wS-$wC-6+"px")
				}
			};
			if (mouseY>$hC/2 && mouseY<$hS-$hC/2) {//判断Y轴，小放大镜出现的位置
				$(".clond_move").css("top",mouseY-$hC/2+"px");
				$(".glassPic").css("background-position-y","-"+(mouseY-$hC/2)*scale+'px');
			} else{
				if(mouseY<$hC/2){
					$(".clond_move").css("top","0px")
				}else{
					$(".clond_move").css("top",$hS-$hC-6+"px")
				}
			};
		},
		"mouseleave":function(){
//			console.log("出去");
			$(".clond_move").css("display","none");
			$(".glassPic").stop().hide();
		}})
	};
	//加减商品
	addJian();
	function addJian(){
		$(".jia").on("click",function(){
			var num = parseInt($("#buynum").val())+1;
			$("#buynum").val(num);
		});
		$(".jian").on("click",function(){
			var num = parseInt($("#buynum").val())-1;
			if(num <= 1){
				num = 1;
			}
			$("#buynum").val(num);
		});
	}
	//回到顶部
	backTop();
	function backTop(){
		$(window).scroll(function(){
			var $t = $("body").scrollTop();
			if($t > 650){
				$(".back2top").css("display","block");
			}else{
				$(".back2top").css("display","none");
			};
			xiding($t);
		})
		$(".backTop").on("click",function(){
			$("html,body").animate({
				scrollTop:0
			},600)
		});
	}
	//吸顶效果
	function xiding($t){
		if($t>800){
			$(".detail_left>.spxq").css({
				"position":'absolute',
				"left":"0px",
				"top":($t-803)+"px",
				"z-index":9000
				})
		}else{
			$(".detail_left>.spxq").css("position","static");
		};			
	};
	//商品 详情、商品评价、商品咨询切换
	$(".detail_left>.spxq").find("li").not(':last').on("click",function(){
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
		console.log($(this).index())
		switch($(this).index()){
			case 0:
				$(".goodsummarize,.spxx,.pic0,.goodsEvaluate,.zixun,.EvaluateList").show();
				break;
			case 1:
				$(".goodsummarize,.spxx,.pic0,.zixun").hide();
				$(".goodsEvaluate,.EvaluateList").show();
				break;
			case 2:
				$(".goodsummarize,.spxx,.pic0,.goodsEvaluate,.EvaluateList").hide();
				$(".zixun").show();
				break;
		}
	});
	//评论加心
	$(".starLevel").find("span").on("mouseenter",function(){
		var $index = $(this).index()+1;
		$(this).parent().find("span:lt("+$index+")").addClass('hovers');
		$(this).parent().find("span:gt("+($index-1)+")").removeClass('hovers');
	})
	//发表评论
	pinglun();
	function pinglun(){
		var myUserName = "myUserName";
		var myPwd = "myPwd"
		var isLogin = "isLogin";
		$(".tijiaopinlun").on('click',function(){
		//判断用户是否登陆
			if(getCookie(isLogin) == 0){
				alert("请登陆后在发表评论！")
			};
			if(getCookie(isLogin) == 1){
				var username = getCookie(myUserName);
				var $word = $("textarea").val();
				createPingLun($word,username);
				$("textarea").val("");
			};
		});
	}
	function createPingLun($word,username){
		$(".elist").append(
							"<li><div class='buerpic'><div><img src='../img/phto.png'/></div><span class='name'>"
							+username+
							"</span></div><div class='viewcontent'><i></i><p><img src='../img/dianzan1.gif'/></p><p class='nameWord'>"
							+$word+
							"</p></div></li>"
							)
	};
	//添加商品到购物车
	addGood2ShopCar(5);
	function addGood2ShopCar($index){
		$(".addshopcar2").find("li").eq(1).find("a").on("click",function(){
			var isLogin = "isLogin";
			if(getCookie(isLogin) == 1){
				var goodMessage = "goodMessage";
				var isbuy = "isbuy";
				var goods = {
					img: $(".small_pic_list").find("li").eq($index).find("img").attr("src"),
					goodname: $(".goodname").html(),
					goodnum: $(".goodsnum").html(),
					goodprise: $(".goodprise>span").html(),
					buynum: $("#buynum").val()
				}
				var strgoods = JSON.stringify(goods);
//				console.log(strgoods);
				addCookie(goodMessage,strgoods,5);
				addCookie(isbuy,1,5);
				alert("加入购物车成功！")
			}else{
				alert("请登陆后在添加商品到购物车！！");
			}
		});
	};
	//收藏功能
	function collect($index){
		var goods = {
			img: $(".small_pic_list").find("li").eq($index).find("img").attr("src"),
			goodname: $(".goodname").html(),
			goodnum: $(".goodsnum").html(),
			goodprise: $(".goodprise>span").html(),
			buynum: $("#buynum").val()
		}
		var strgood = JSON.stringify(goods);
		return strgood;
	};
	$(".collect").on("click",function(){
		var isLogin = "isLogin";
			if(getCookie(isLogin) == 1){
				var collectGood = "collectGood";
				var isCollect = "isCollect";
				addCookie(collectGood,collect(0),5);
				addCookie(isCollect,1,5);
				alert("加入收藏夹成功");
			}else{
				alert("请登陆后在添加商品到购物车！！");
			}
		
	});
	
}
$(function(){
	$("#header1").load("../header.html");
	$("#last").load("../footer.html #footer1");
	start();
})
